﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibrarySync2.Common.Interfaces;
using LibrarySync2.Common.Enum;

namespace LibrarySync2.ChildForms
{
    public class MediaFileUpdateFormListItem : IUpdateFormListItem
    {
        protected const long OneMeg = 1048576;

        #region IUpdateFormListItem Members

        public bool IsSelected { get; set; }

        public MediaFileUpdateType MediaFileUpdateType { get { return ItemUpdate.MediaFileUpdateType; } }

        public IFileSystemItemUpdate ItemUpdate { get; protected set; }

        public string Name { get { return ItemUpdate.MediaFile.Name; } }

        public string UniqueId { get { return ItemUpdate.MediaFile.Id; } }

        private long _size = 0L;

        public long Size
        {
            get
            {
                if (_size == 0L)
                {
                    _size = ItemUpdate.MediaFile.CalculateFullSize() / OneMeg;
                }
                return _size;
            }
        }

        #endregion

        public MediaFileUpdateFormListItem(bool isSelected, IFileSystemItemUpdate itemUpdate)
        {
            IsSelected = isSelected;
            ItemUpdate = itemUpdate;
        }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            var listItem = obj as IUpdateFormListItem;
            if (listItem == null)
                return 1;

            return this.Name.CompareTo(listItem.Name);
        }

        #endregion
    }
}
